#include<stdio.h>
typedef struct team
{
	char name[26];
	int win;
	int lose;
	int score;
	int winball;
}TEAM;
void swap(TEAM *p1,TEAM *p2)
{
	TEAM temp=*p1;
	*p1=*p2;
	*p2=temp;
	return;
}
int comp(TEAM *p1,TEAM *p2)
{
	if(p1->score>p2->score)
	return 1;
	else if(p1->score<p2->score)
	return 0;
	else
	{
		if(p1->winball>p2->winball)
		return 1;
		else if(p1->winball<p2->winball)
		return 0;
		else
		{
			if(p1->win>p2->win)
			return 1;
			else
			return 0;
		}
	}
}
void sort(TEAM *team[],int n)
{
	for(int i=0;i<n;i++)
	{
		int high=i;
		for(int j=i+1;j<n;j++)
		{
			if(comp(team[high],team[j])==0)
			high=j;
		}
		swap(team[high],team[i]);	
	}
	return;
}
int main()
{
	TEAM teams[4];
	for(int i=0;i<4;i++)
	{
		scanf("%s %d %d %d",&teams[i].name,&teams[i].win,&teams[i].lose,&teams[i].score);
		teams[i].winball=teams[i].win-teams[i].lose;
	}
	TEAM *team[4];
	for(int i=0;i<4;i++)
	{
		team[i]=&teams[i];
	}
	sort(team,4);
	for(int i=0;i<4;i++)
	{
		printf("%s\n",team[i]->name);
	}
	return 0;
}
